//
//  BoundsViewController.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/4/10.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "BoundsViewController.h"
/*
 frame和bounds:都是用来描述一块区域的
 frame:描述可视范围
 bounds：描述可视范围在内容的区域
 子空间都是相对于内容的
 */



@interface BoundsViewController ()

@property (nonatomic, strong) UIView *redView;
@property (nonatomic, strong) UIView *myScrollview;
@end

@implementation BoundsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
//    UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
//    redView.backgroundColor = [UIColor blueColor];
//    [self.view addSubview:redView];
//    _redView = redView;
//
//
//    UISwitch *swithView = [[UISwitch alloc]init];
//    swithView.on = YES;
//    [_redView addSubview:swithView];
//
//    NSLog(@"%@",NSStringFromCGRect(redView.bounods));
//    _redView.layer.anchorPoint = CGPointMake(0, 0);
//    _redView.layer.position = CGPointMake(0, 0);
    
    UIView *myScrollview = [[UIView alloc]initWithFrame:self.view.bounds];
    
    // 添加手势
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
    [myScrollview addGestureRecognizer:pan];
    _myScrollview = myScrollview;
    
    
    UISwitch *s = [[UISwitch alloc]initWithFrame: CGRectMake(0, 100, 0, 0)];
    s.on = YES;
    [_myScrollview addSubview:s];
    
    [self.view addSubview:_myScrollview];
    
}

-(void)pan:(UIPanGestureRecognizer *)pan{
    //修改bounds
    CGPoint transP = [pan translationInView:pan.view];
    
    CGRect bounds = _myScrollview.bounds;
    
    bounds.origin.y -= transP.y;
    
    _myScrollview.bounds = bounds;
    // 复位
    [pan setTranslation:CGPointZero inView:pan.view];
    
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//    CGRect bounds = _redView.bounds;
//    bounds.origin.y += 10;
//    _redView.bounds = bounds;

    
    [UIView animateWithDuration:1 animations:^{
        _redView.transform = CGAffineTransformMakeRotation(M_PI);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
